//
//  WBVisitorTableViewController.swift
//  WBWeiBo
//
//  Created by 王斌 on 16/7/9.
//  Copyright © 2016年 王斌. All rights reserved.
//

import UIKit

class WBVisitorTableViewController: UITableViewController {
    
    //  登录标识
    var isLongin:Bool = WBUserAccountViewModel.shareUserAccount.isLogin
    
    //  访客视图
    var visitorView:WBVisitorView?
    
    override func loadView() {
        
        if isLongin{
            super.loadView()
        }else{
            
            //  未登录,需要提供访客视图
            visitorView = WBVisitorView()
            
            //  使用[weak self]解决闭包循环引用问题
            visitorView?.loginClosure = {[weak self] in

                self?.showOAuthLogin()
                
            }
            
            view = visitorView
            
            
            //调用导航栏添加按钮的方法
           setupNavUI()
        }
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    
    //  设置导航视图
    private func setupNavUI(){
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", target: self, action: "registerAction")
        
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", target: self, action: "loginAction")
    }
    
    
    
    // MARK:    --点击事件
    @objc private func registerAction() {
        print("注册按钮点击了")
        
        showOAuthLogin()
        
    }
    @objc private func loginAction() {
        
        print("登录按钮点击了")
        showOAuthLogin()
    }
    
    
     //  OAuth登录页面
    private func showOAuthLogin(){
        let oAuthVC = WBOAuthViewController()
        let nav = UINavigationController(rootViewController: oAuthVC)
        
        presentViewController(nav, animated: true, completion: nil)
    }

    

}
